#include<string>
#include<iostream>
using namespace std;
class Solution
{
public:
    string convert(string s, int numRows)
    {
        //根据numRows来申请字符串数组,数组长度为numRows
        string *string_list = new string[numRows];
        for (int i = 0; i < numRows; i++)
        {
            string_list[i] = "";
        }
        int len = s.size();
        //遍历字符串
        int ptr = 0;
        bool incre = true; //ptr应该增加还是下降
        for (int i = 0; i < len; i++)
        {
            //计算s[i]应该追加到string_list哪一项中
            string_list[ptr] += s[i];
            if (0 == ptr && !incre)
            { //ptr是零且是下降，则将其反转
                incre = true;
            }
            //ptr是numRows-1 且是上升,将其反转
            if (numRows - 1 == ptr && incre)
            {
                incre = false;
            }
            //控制ptr
            if (incre && ptr < numRows - 1)
            {
                ptr++;
            }
            else if (!incre && ptr > 0)
            {
                ptr--;
            }
        }
        string back = "";
        for (int i = 0; i < numRows; ++i)
        {
            back = back + string_list[i];
        }
        return back;
    }
};

int main(int argc,char**argv){
    Solution *solution = new Solution();
    string back=solution->convert("AB",1);
    cout<<"back:"<<back;
    delete solution;
    return 0;
}
